import request, { RequestDto, PageData, PageParams } from './request'
import qs from 'qs'

export interface ColumnDto {
  author: string
  avatar?: {
    url: string
    _id: string
  }
  createdAt: string
  description: string
  featured: boolean
  key: number
  title: string
  __v: number
  _id: string
}
export interface PatchColumnParams {
  title: string
  description?: string
  avatar?: string
}

// 获取专栏分页数据
export function getPageColumns(data: PageParams): Promise<RequestDto<PageData<ColumnDto>>> {
  return request.get(`/columns?${qs.stringify(data)}`)
}
// 获取专栏详情
export function getColumnDetail(id: string): Promise<RequestDto<ColumnDto>> {
  return request.get(`/columns/${id}`)
}
// 更新专栏信息
export function updateColumnData(
  id: string,
  data: PatchColumnParams
): Promise<RequestDto<ColumnDto>> {
  return request.patch(`/columns/${id}`, data)
}
